package com.cy;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.sound.midi.Soundbank;
import java.util.PrimitiveIterator;

@SpringBootApplication
public class NacosConfigApplication {

    private static Logger logger = LoggerFactory.getLogger(NacosConfigApplication.class);
    public static void main(String[] args) {
        SpringApplication.run(NacosConfigApplication.class, args);
        logger.info("~~~info~~~"); //debug<info<error,springboot默认日志级别为info
        logger.debug("~~~debug~~~");
        logger.error("~~~error~~~");
    }
    //@RefreshScope是spring中国的@Scope的升级版(特殊的@Scope)
    //@RefreshScope描述Controller类时,假如配置中心的配置发生变化.
    //我们在对此类中的url资源进行访问时,会重新构建此对象.
    @RefreshScope  //当配置信息发生变化时系统会基于@Value注解读取的值对属性进行重新赋值
    @RestController //@RestController是一个升级版的Controller
    public class NacosConfigController{ //此对象只创建一次
        @Value("${logging.level.com.cy:error}")//这里error表示没有取到日志级别时给一个默认的级别
        private String logLevel;
        @GetMapping("/config/log/level")
        public String doLogLevel(){
            System.out.println("log.level="+logLevel);
            //通过如下日志输出检测,在配置中心改了日志级别是否会影响下面日志的输出
            logger.info("--info");
            logger.debug("--debug");
            logger.error("--error");
            return "log level is"+ logLevel;

        }
    }

}
